import React from 'react';
import { ActivityIndicator, FlatList, Image, RefreshControl, Text, View } from 'react-native';
interface ClassRecord {
	date: string;
	week: string;
	grade: string;
	class_name: string;
	teacher_name: string;
	subject_name: string;
	section: string;
	start_time: string;
	finish_time: string;
}
export default function tpl(a: <T>(action: string, ...args: unknown[]) => ((...args: unknown[]) => void), s: (...class_names: string[]) => {}, d: (d: string) => string | unknown[]) {
	const arr = d('res') as ClassRecord[];
	if (arr) {
		const page_no = Number(d('page_no'));
		const len = arr.length;
		const page_size = 20;
		const new_len = Number(d('new_len'));
		return (
			<FlatList refreshControl={
				<RefreshControl
					onRefresh={a('a001')}
					colors={['#ff0000']}
					enabled={true}
					progressBackgroundColor="#ffffff"
					refreshing={false}
				/>
			} onEndReached={a('a002', page_no + 1)}
				onEndReachedThreshold={0.1} data={arr} renderItem={({ item, index }) => {
					return (<View>
						<View style={{ borderBottomColor: '#ddd', borderBottomWidth: 1, borderTopColor: '#ddd', borderTopWidth: 1, marginTop: 20, backgroundColor: '#fff' }}>
							<View style={s('v1')}>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}><Text style={{ letterSpacing: 10, }}>日期</Text>：</Text>
									<Text style={{ width: 150 }}>{item.date}</Text>
								</View>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}><Text style={{ letterSpacing: 10, }}>星期</Text>：</Text>
									<Text>{item.week}</Text>
								</View>
							</View>
							<View style={s('v1')}>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}>年级名称：</Text>
									<Text style={{ width: 150 }}>{item.grade}</Text>
								</View>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}>班级名称：</Text>
									<Text>{item.class_name}</Text>
								</View>
							</View>
							<View style={s('v1')}>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}>教师姓名：</Text>
									<Text style={{ width: 150 }}>{item.teacher_name}</Text>
								</View>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}><Text style={{ letterSpacing: 10, }}>科目</Text>：</Text>
									<Text>{item.subject_name}</Text>
								</View>
							</View>
							<View style={s('v1')}>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}>上课时间：</Text>
									<Text style={{ width: 150 }}>{item.start_time}～{item.finish_time}</Text>
								</View>
								<View style={{ flexDirection: 'row' }}>
									<Text style={s('text1')}><Text style={{ letterSpacing: 10, }}>节次</Text>：</Text>
									<Text>{item.section}</Text>
								</View>
							</View>
						</View>
						{
							(() => {
								if (len === index + 1 && len > page_size - 1) {
									if (new_len) {
										return (
											<View style={s('footer')}>
												<ActivityIndicator />
												<Text>正在加载更多数据...</Text>
											</View>
										);
									} else {
										return (
											<View style={{ height: 30, backgroundColor: '#f4f4f4', position: 'absolute', bottom: 0, left: 0, right: 0 }}>
												<Text style={{ color: '#999999', fontSize: 14, marginTop: 5, marginBottom: 5, textAlign: 'center' }}>
													没有更多数据了
											</Text>
											</View>
										);
									}
								}
							})()
						}
					</View >);
				}} />
		);
	} else if (!arr) {
		return (<View style={s('footer1')}>
			<ActivityIndicator
				animating={true}
				color='blue'
				size="large"
			/>
		</View>);
	} else {
		return (<View style={s('page')}>
			<Image source={require('../../imgs/wushuju.png')} style={{ width: 80, height: 80 }} />
			<Text style={{ fontSize: 20 }}>没有符合当前筛选条件的数据</Text>
		</View>);
	}
}
